﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DungeonCraft.DataModel.Abilities.Interfaces;
using DungeonCraft.DataModel.Tools;

namespace DungeonCraft.DataModel.Abilities
{
    public class Jump : IAbility 
    {
        private CallbackTimer timer;
        private Player player;

        public Jump(CallbackTimer timer)
        {
            this.timer = timer;
        }
        public string Execute(DataModel.Interfaces.ILevel level, Player player, IGuard gaurd, Location mouseLocation)
        {
            if (!gaurd.Check(level, player, this))
                return "Could not jump";
            timer.Reset();
            this.player = player;
            switch (player.Direction)
            {
                case Player.Directions.Up:
                    timer.TickCallBack = JumpUp;
                    break;
                case Player.Directions.Down:
                    timer.TickCallBack = JumpDown;
                    break;
                case Player.Directions.Left:
                    timer.TickCallBack = JumpLeft;
                    break;
                case Player.Directions.Right:
                    timer.TickCallBack = JumpRight;
                    break;
            }
            timer.EndCallBack = Land;
            player.Jumping = true;
            timer.tickTime = 5;
            timer.NumberOfTicks = 15;
            timer.Start();
            return "Jumping";
        }

        public void JumpUp()
        {
            player.Move(0, -player.Speed * 2);
        }

        public void JumpDown()
        {
            player.Move(0, player.Speed * 2);
        }

        public void JumpLeft()
        {
            player.Move(-player.Speed * 2, 0 );
        }

        public void JumpRight()
        {
            player.Move(player.Speed * 2, 0);
        }

        public void Land()
        {
            player.Jumping = false;
            player.StartJumpCooldown(new CallbackTimer(50, 2));
        }

        public bool Drawable()
        {
            return false;
        }
    }
}
